<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS中的this</title>
</head>
<body>
    <script>

        // function foo1(){
        //     let name =''
        //     console.log('========='+this);

        //     function foo2(){
        //         console.log('----------'+this);
        //     }

        //     foo2();
        // }

        // foo1();


        let user = {
            foo1: function () {
                console.log('1. '+this);

                let _this = this;

                function  foo2() { 
                    console.log('2. '+_this);
                 }
                 foo2();//这里就相当于window.foo2() 因为没有对象直接调用
              }
        }

        user.foo1();


    </script>
</body>
</html>